package admin.dao;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import viewmodel.ExamsEditStatus;

import model.Connect;
import model.Exams;

public class ExamsDAO {
	public static List<Exams> getAllExams(){
		ArrayList<Exams> listExams = new ArrayList<Exams>();
		String sql = "SELECT * FROM bode";
		try{
			Statement state = Connect.getConnection().createStatement();
			ResultSet result = state.executeQuery(sql);
			while(result.next()){
				Exams exams = new Exams(result.getInt("id"), result.getString("name_bode"), result.getString("name_made"), result.getString("ma_made"), result.getString("ma_bode"));
				listExams.add(exams);
			}
			result.close();
			state.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
		return listExams;
	}

	public static void updateExams(ExamsEditStatus ees) {
		String sql = "UPDATE `bode` SET name_bode='"+ees.getExams().getTenBode()+"',name_made='"+ees.getExams().getTenDe()+"' WHERE id="+ees.getExams().getId();
		try{
			Statement state = Connect.getConnection().createStatement();
			state.executeUpdate(sql);
			state.close();
		}catch (Exception e) {
		}
	}

	public static void removeExams(Exams exams) {
		String sql = "DELETE FROM `bode` WHERE id="+exams.getId();
		try{
			Statement state = Connect.getConnection().createStatement();
			state.executeUpdate(sql);
			state.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

	public static void addExams(Exams exams) {
		String sql = "INSERT INTO `bode` (name_bode,name_made,ma_bode,ma_made) VALUES('"+exams.getTenBode()+"','"+exams.getTenDe()+"','"+exams.getMaBode()+"','"+exams.getMaDe()+"')";
		try{
			Statement state = Connect.getConnection().createStatement();
			state.executeUpdate(sql);
			state.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
	}
}
